from bcat.process.executable import Executable, IExecutable
class Python(Executable):
    @staticmethod
    def default() -> IExecutable:
        return Python()
    @staticmethod
    def v3() -> IExecutable:
        return Python("python3")
    @staticmethod
    def v2() -> IExecutable:
        return Python("python2")

        
    def __init__(self, pyname = "python"):
        super().__init__()
        self.binary(pyname)

class Ping(Executable):
    @staticmethod
    def local_host(times: int = 0) -> IExecutable:
        p = Ping()
        if times > 0:
            p.args(["127.0.0.1", f"-c {times}"])
        else:
            p.args("127.0.0.1")
        return p
            
    
    def __init__(self):
        super().__init__()        
        self.binary("ping")


from bcat.process.error import CommandNotFoundError
import unittest
class TestCase(unittest.TestCase):
    def test_default(self):
        Python.v3().args(["-m unittest", "./executable.py"]).execute()
        Python.v3().directory("/usr/bin").args(["-m unittest", "./executable.py"]).execute()

    def test_v3(self):
        Python.default().args(["-m unittest", "./executable.py"]).execute()
        Python.default().directory("/usr/bin").args(["-m unittest", "./executable.py"]).execute()

    def test_v2(self):
        Python.v2().args(["-m unittest", "./executable.py"])
        self.assertRaises(CommandNotFoundError, Python.v2().args(["-m unittest", "./executable.py"]).execute)

        Python.v2().directory("/usr/bin").args(["-m unittest", "./executable.py"])
        self.assertRaises(CommandNotFoundError, Python.v2().directory("/usr/bin").args(["-m unittest", "./executable.py"]).execute)

